package cn.lingyangwl.agile.food.core.controller.app;

import cn.lingyangwl.agile.model.constants.CommonCons;
import cn.lingyangwl.agile.model.module.tenant.TenantContext;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.agile.food.model.entity.ShopStore;
import cn.lingyangwl.agile.food.model.rqrs.store.StoreListReq;
import cn.lingyangwl.agile.food.model.rqrs.store.StorePageReq;
import cn.lingyangwl.agile.food.model.rqrs.store.StoreResp;
import cn.lingyangwl.agile.food.core.service.StoreService;
import cn.lingyangwl.framework.core.response.Resp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 门店
 * 
 * @author shenguangyang
 */
@Api(tags = "门店")
@RestController
@RequestMapping("/app/store")
public class AppShopStoreController {
    @Resource
    private StoreService storeService;

    @ApiOperation(value = "app-分页门店")
    @GetMapping("/pageStore")
    @RamResource(action = "appShop:store:query", name = "app-查询门店", type = ActionType.READ)
    public Resp<IPage<StoreResp>> pageStore(@Validated StorePageReq req) {
        req.setStatus(CommonCons.UseStats.NORMAL);
        return Resp.ok(storeService.pageStore(req));
    }

    @ApiOperation(value = "app-分页门店")
    @GetMapping("/listStore")
    @RamResource(action = "appShop:store:query", name = "app-查询门店", type = ActionType.READ)
    public Resp<List<StoreResp>> listStore(@Validated StoreListReq req) {
        return Resp.ok(storeService.listStore(req));
    }

    @ApiOperation(value = "app-查询门店")
    @GetMapping("/getStore")
    @RamResource(action = "appShop:store:query", name = "app-查询门店", type = ActionType.READ)
    public Resp<ShopStore> getStore() {
        return Resp.ok(storeService.getTenantRefStore(TenantContext.get().getTenantId()));
    }
}
